package ca.mcgill.schedulability.singleevent.functional;

import java.util.ArrayList;
import java.util.List;

import ca.mcgill.model.digraph.Digraph;
import ca.mcgill.model.digraph.DigraphEdge;
import ca.mcgill.model.functional.Transition;


public class DemandTupleSet {

	private List<DemandTuple> dts;
	
	public DemandTupleSet(List<DemandTuple> dts){
		this.dts = dts;
	}

	public List<DemandTuple> getDemandTuples() {
		return this.dts;
	}

	public void setDemandTuples(List<DemandTuple> dts) {
		this.dts = dts;
	}

	public void addDemandTuple(DemandTuple dt) {
		this.dts.add(dt);
	}
	
	
	public void removeDemandTuple(int DTindex) {
		this.dts.remove(DTindex);
	}
	
	public void addDemandTupleSet(List<DemandTuple> dtsNew) {
		this.dts.addAll(dtsNew);
	}
	
	
	public void resetDemandTupleSet(Digraph myDigraph) {
		
		List<Boolean>  dummyDTboolean = new ArrayList<Boolean>();
		boolean addTrue = true;
		dummyDTboolean.add(addTrue);
		
		DemandTuple dummyDT = new DemandTuple(-1,-1,null,dummyDTboolean); // add dummy in case is empty
		this.dts.add(dummyDT);
		
		this.dts.clear();
		
		for (Transition transition : myDigraph.getVertices() ) {
			
			boolean addTakenEdge = false;
			List<Boolean>  TakenEdgesBoolean = new ArrayList<Boolean>();

			// the outgoing edges of toNext transitions should be marked as notTaken
			for (DigraphEdge edge2 : myDigraph.getEdges()) {
				if (transition.equals(edge2.getSrcVertex())) {
					TakenEdgesBoolean.add(addTakenEdge);
				}
			}
			
			// DT <- {e(gamma), gamma | gamma in Digraph} (i.e. all vertices of Digraph)
			DemandTuple DT = new DemandTuple(transition.getAction().getWCET(), transition.getAction().getWCET() , transition, TakenEdgesBoolean); // initialOffsetZero
			this.dts.add(DT);
		}
		
	}
	
	
	public void resetDemandTripleSet(Digraph myDigraph) {
		
		List<Boolean>  dummyDTboolean = new ArrayList<Boolean>();
		boolean addTrue = true;
		dummyDTboolean.add(addTrue);
		
		DemandTuple dummyDT = new DemandTuple(-1,-1,null,dummyDTboolean); // add dummy in case is empty
		this.dts.add(dummyDT);
		
		this.dts.clear();
		
		for (Transition transition : myDigraph.getVertices() ) {
			
			boolean addTakenEdge = false;
			List<Boolean>  TakenEdgesBoolean = new ArrayList<Boolean>();

			// the outgoing edges of toNext transitions should be marked as notTaken
			for (DigraphEdge edge2 : myDigraph.getEdges()) {
				if (transition.equals(edge2.getSrcVertex())) {
					TakenEdgesBoolean.add(addTakenEdge);
				}
			}
			
			// DT <- {e(gamma), gamma | gamma in Digraph} (i.e. all vertices of Digraph)
			DemandTuple DT = new DemandTuple(transition.getAction().getWCET(), transition.getRelativeDeadline() , transition, TakenEdgesBoolean); // initialOffsetZero
			this.dts.add(DT);
		}
		
	}
	
	

}